package com.haoshuang.zhouzhoubang.ui.page.mine.invite.create

import androidx.core.widget.addTextChangedListener
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ItemCreateTeamMemberBinding
import com.haoshuang.zhouzhoubang.ui.activity.AddPhoneNumberBean
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.imageResource
import com.mufeng.libs.utils.view.visibleOrGone
import com.mufeng.libs.utils.view.visibleOrInvisible


/**
 *
 */
class CreateTeamMemberAdapter(
    data: MutableList<AddPhoneNumberBean>,
    private val minus: (position: Int) -> Unit
) : BaseBindingQuickAdapter<AddPhoneNumberBean, ItemCreateTeamMemberBinding>(data) {
    override fun onBindViewHolder(
        holder: BaseBindingHolder,
        position: Int,
        item: AddPhoneNumberBean?
    ) {
        holder.getViewBinding<ItemCreateTeamMemberBinding>().apply {
            etPhone.tag = position
            etPhone.setText(items[etPhone.tag as Int].phoneNumber)
            etPhone.addTextChangedListener {
                items[etPhone.tag as Int].phoneNumber = etPhone.text.toString()
            }
            ivAddMinus.imageResource =
                if (position == 0) R.mipmap.icon_insure_add else R.mipmap.icon_insure_minus
            ivAddMinus.visibleOrInvisible(position != 0)

            ivAddMinus.click {
                if (position == 0) {
                    // 添加
//                    add(etPhone.text.toString(), position)
                } else {
                    // 移除
                    minus(position)
                }
            }
        }
    }

}

